import React, { Component } from "react";
import { connect } from "react-redux";
import { setDisListData , clearDisListData} from "@/store/action/discover";
import { renderRoutes } from "react-router-config";
import ItemList from "./IitemList";
import {NavLink} from 'react-router-dom'
import {Listnew} from '../style';
@connect(
  (state) => ({ disListData: state.getIn(["discover", "disListData"]).toJS() }),
  { setDisListData , clearDisListData }
)
class List extends Component {

  changeSubRouter(){
    let type = 283;
    switch (this.props.location.pathname) {
      case '/discover/today':
        type = 283;
        break;
      case '/discover/basketball':
        type = 347;
        break;
      case '/discover/video':
        type = 281;
        break;
      case '/discover/information':
        type = 270;
        break;
      case '/discover/trend':
        type = 318;
        break;
    
      default:
        break;
    }
    return type;
  }

  componentDidMount(){
    this.props.history.listen(location => {
      this.props.clearDisListData();
    })
  }
  render() {
    return (
      <Listnew>
        <div className="menu-list">
          <div className="link" >
            <NavLink to="/discover/today">
              今日推荐
            </NavLink>
            <NavLink to="/discover/basketball">
              篮球
            </NavLink>
            <NavLink to="/discover/video">
              视屏
            </NavLink>
            <NavLink to="/discover/information">
              最新资讯
            </NavLink>
            <NavLink to="/discover/trend">
              潮流风向
            </NavLink>
          </div>
          <div className="tagbtn"></div>
        </div>


        <div style={{height:'100%'}}>
          {renderRoutes(this.props.route.routes, {
            item: ItemList,
            data: this.props.disListData,
            getData: (page=1) =>this.props.setDisListData({
                tag_id: this.changeSubRouter(),
                page,

              }),
          })}
        </div>
      </Listnew>
    );
  }
}

export default List;
